<%@ page language="java"  pageEncoding="utf-8"%>
<%@ include file="/commons/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head>
<%@ include file="/commons/header.jsp"%>
</head>

<body>
    
    <s:form action="/Users/save.action" theme="simple" onsubmit="return validate();">
    <s:hidden name="user.state" value="RNA"></s:hidden>
 
    <div class="main">
        <div class="mod formAddUsr">
            <div class="hd"><p class="ntc"> <c:out value='${sessionScope.userName}' />  </p></div>
            <div class="bd">
                <dl class="container">
                    
                    <dt><em>*</em>帐号名称：</dt>
                    <dd><s:textfield id="userName" name="userName" cssClass="txt4" onblur="validateIsExist(this);"></s:textfield><span id="usercode_msg" class="tip_red"></span></dd>
                    
                    <dt><em>*</em>帐号密码：</dt>
                    <dd><s:textfield id="password" name="password" cssClass="txt4" ></s:textfield><span id="usercode_msg" class="tip_red"></span></dd>
                    
                    <dt><em>*</em>重复输入密码：</dt>
                    <dd><s:textfield id="password1" name="password1" cssClass="txt4"  ></s:textfield><span id="usercode_msg" class="tip_red"></span></dd>
                    
                    
                    <dt><em>*</em>所属工作组：</dt>
                    <dd><s:textfield id="person_name" name="user.person_name" cssClass="txt4"  ></s:textfield><span id="usercode_msg" class="tip_red"></span></dd>
                    
                    
                     
                    
                    <dd><input type="submit" value="保存"/></dd>
                </dl>
            </div>
        </div>
    </div>
    </s:form>
    
    
    <script type="text/javascript">
    	function validate(){
    	
    		var person_code = $('#person_code');
    		if(person_code.val() == ''){
    			alert('请输入登录名');
    			person_code.focus();
    			return false;
    		}
    		
    		var person_name = $('#person_name');

    		//提交时验证用户名是否存在
    	/*	if(!validateIsExist(person_name.get(0))){
    			return false;
    		}
    		
    		var comp_select = $('#comp_select');
    		if(comp_select.val() == ''){
    			alert('请选择公司');
    			comp_select.focus();
    			return false;
    		}
    		
    		var dept_select = $('#dept_select');
    		if(dept_select.val() == ''){
    			alert('请选择部门');
    			dept_select.focus();
    			return false;
    		}
    		
    		
    	*/
    		
    		return true;
    	}
    	
    	var result = false;
    	
    	function validateIsExist(person_name){
    		
    		var usercode_msg = $('#usercode_msg');
        	if(person_name.value == ''){
        		usercode_msg.text("请输入姓名");
        		person_name.focus();
        		return false;
        	}
    		
    		$.ajax({
    			type:"GET",
    			url:"${ctx}/Users/checkUser.action",
    			data:"userName=" + person_name.value ,
    			success:function(msg){
    				if(msg == '-1'){
    					usercode_msg.text("请输入姓名");
    					result = false
    				}else if(msg == '0'){
    					usercode_msg.text("可以使用该姓名");
    					result = true;
    				}else{
    					usercode_msg.text("姓名已存在，请重新输入");
    					result = false
    				}
    			}	
    		});
    		
    		return result;
    	}
    	
    	function validateCode(){
    		
    	}
    	
    	function findCompByRegion(region){
			if(region.value == ''){
				return ;
			}
			
			$('#dept_select').children().remove();
		
			$.ajax({
    			type:"POST",
    			url:"async_findCompByRegion.action",
    			data:"company.dep_id=" + region.value,
    			dataType:"html",
    			success:function(obj){
    				var options = decodeURI(obj);
    				$('#dept_select').append("<option value=''>请选择</option>");
    				$('#dept_select').append(options);
    			}
    		});
		}
    </script>
</body>
</html>

